package EA.testproblems;
import EA.*;
import RKUjava.util.*;

/*
  Michalewicz Function
  
  Created: 24. Feb. 2000
  @version 1.0
  @author Rene Thomsen
*/

/*
 Michalewicz's objective function from article:
 "Evolutionary Optimization Through Extinction Dynamics"
 with d=10
 */
public class Michalewicz extends NumericalProblem {
    
    // Easier way to build max and min
    private double[][] lmax = new double[0][10];
    private double[][] lmin = new double[0][10];
    
    public Michalewicz() {
	super();
	
	double[] optimas;
	name = "Michalewicz function";
	objectivefunction = new NumericalFitness() {
		public double Fitness_calcFitness_inner(double[] realpos) {
		    double fit = 0;
		    //calculate fitness for each individual
		    for (int i=1; i<11; i++) {
			fit= fit + Math.sin(realpos[i-1])*
			    Math.pow(Math.sin((i*Math.pow(realpos[i-1],2)/Math.PI)),20);
		    }
		    return fit;
		};
      };
	
	dimensions = 10;
	ismaximization = true;
	optimumradius = 0.2;

	intervals = new Interval[dimensions];
	for (int i=0; i<dimensions; i++)
	    intervals[i] = new Interval(0.0, Math.PI);


	// Set up known maxima
	knownmaxima = new NumericalOptimum[lmax.length];
	for (int i=0;i<lmax.length;i++) {
	    optimas = new double[dimensions];
	    for (int j=0;j<dimensions;j++) {
		optimas[j] = lmax[i][j];
	    }
	    knownmaxima[i] = new NumericalOptimum(optimas, objectivefunction.calcFitness(optimas), true, false, i);
	}
	
	// Set up known minima
	knownminima = new NumericalOptimum[lmin.length];
	
	for (int i=0;i<lmin.length;i++) {
	    optimas = new double[dimensions];
	    for (int j=0;j<dimensions;j++) {
		optimas[j] = lmin[i][j];
	    }
	    knownminima[i] = new NumericalOptimum(optimas, objectivefunction.calcFitness(optimas), false, false, i);
	}
	
    }
}
